{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from geoscilabs.dcip.DC_Pseudosections import DC2DfwdWidget\n",
    "from IPython.display import display"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Inverting Data\n",
    "\n",
    "In this final widget you are able to forward model the apparent resistivity of a cylinder embedded in an otherwise uniform halfspace. Pseudo-sections of the apparent resistivity can be generated using dipole-dipole, pole-dipole, or dipole-pole arrays to see how survey geometry can distort the size, shape, and location of conductive bodies in a pseudo-section.  Due to distortion and artifacts present in pseudo-sections trying to interpret them directly is typically difficult and dangerous due to the risk of misinterpretation. Inverting the data to find a model which fits the observed data and is geologically reasonable should be standard practice.   \n",
    "\n",
    "By systematically varying the model parameters and comparing the plots of observed vs. predicted apparent resistivity a parametric inversion can be preformed by hand to find the \"best\" fitting model. Normalized data misfits, which provide a numerical measure of the difference between the observed and predicted data, are useful for quantifying how well and inversion model fits the observed data. The manual inversion process can be difficult and time consuming even with small examples sure as the one presented here. Therefore, numerical optimization algorithms are typically utilized to minimized the data misfit and a model objective function, which provides information about the model structure and complexity, in order to find an optimal solution.\n",
    "\n",
    "Definition of variables:\n",
    "- **$\\rho_1$**: Resistivity of the halfspace\n",
    "- **$\\rho_2$**: Resistivity of the cylinder\n",
    "- **xc**: x location of cylinder center\n",
    "- **zc**: z location of cylinder center\n",
    "- **r**: radius of cylinder\n",
    "- **predmis**: toggle which allows you to switch the bottom pannel from predicted apparent resistivity to normalized data misfit\n",
    "- **suveyType**: toggle which allows you to switch between survey types.\n",
    "- **Run Interact**: Use this button to update your plot\n",
    " \n",
    " ###  **This app can be slow. You need to hit* Run Interact* to update the figure after you made modifications to the parameters**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "a3fbe5c7d1df42cbb6bb0a88cb278d48",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "MyApp(children=(FloatText(value=1000.0, description='$\\\\rho_1$'), FloatText(value=1000.0, description='$\\\\rho_…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "out = DC2DfwdWidget()\n",
    "display(out)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "widgets": {
   "state": {
    "0fbc90051f9c41228104b34c53a306c0": {
     "views": [
      {
       "cell_index": 2
      }
     ]
    }
   },
   "version": "1.2.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
